package com.vvlhw.pptmall.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.vvlhw.pptmall.product.entity.GoodImagesEntity;
import com.vvlhw.pptmall.product.service.GoodImagesService;
import com.vvlhw.common.utils.PageUtils;
import com.vvlhw.common.utils.R;



/**
 * 商品图片表
 *
 * @author lianghanwei
 * @email 15362941982@163.com
 * @date 2020-06-14 16:11:50
 */
@RestController
@RequestMapping("product/goodimages")
@Api(tags = "图片集操作")
public class GoodImagesController {
    @Autowired
    private GoodImagesService goodImagesService;

    /**
     * 列表
     */
//    @RequestMapping("/list")
//    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = goodImagesService.queryPage(params);
//
//        return R.ok().put("page", page);
//    }


    /**
     * 查询商品gid的所有图片
     */
    @ApiOperation("查询某个商品gid的所有图片")
    @GetMapping("/info/{gid}")
    public R info(@PathVariable("gid") Long gid){
        List<GoodImagesEntity> list = new LambdaQueryChainWrapper<>(goodImagesService.getBaseMapper()).eq(GoodImagesEntity::getGid, gid).list();
        return R.ok().put("goodImages", list);
    }

    /**
     * 批量保存图片
     * 因为一般图片集都有好几张
     */
    @PostMapping("/save")
    public R save(@RequestBody GoodImagesEntity[] goodImages){
        goodImagesService.saveBatch(Arrays.asList(goodImages));
        return R.ok();
    }

    /**
     * 修改
     */
//    @RequestMapping("/update")
//    public R update(@RequestBody GoodImagesEntity goodImages){
//		goodImagesService.updateById(goodImages);
//
//        return R.ok();
//    }

    /**
     * 删除
     */
//    @RequestMapping("/delete")
//    public R delete(@RequestBody Long[] iids){
//		goodImagesService.removeByIds(Arrays.asList(iids));
//        return R.ok();
//    }

}
